#####################################################################
# Do Personality Traits Predict Voter Attitudes When Politics Is    #
# Structured Around Conflict? Lessons From Israel                   #
#                                                                   #
# Rivlin-Angert, Yakter, and Sheffer                                #
# Public Opinion Quarterly                                          #
#                                                                   #
# Replication code - Figure E1                                       #
#####################################################################
# To load the data, users should place the relevant csv	file in     #
# in their R working directory (or type the full file paths as      #
# saved on their computer).                                         #
#####################################################################

## Required packages
library(foreign)
library(dplyr)
library(ggplot2)

## set-up data
# load data (data created from descriptive stats extracted from the main file)
dat <- read.csv("Angert-Rivlin, Yakter, Sheffer POQ - figure E1 data.csv")
# re-order factor levels so they appear in desired order in the graph
dat$trait <- factor(dat$trait, level=c("agree","consc", "stabi","extra","openn"))
dat$religion <- factor(dat$religion,levels=c("full","sec","trad","relig","vrelig"))

## plot (Figure E1)
# facet labels for subtitles
labeller_bf <- labeller(trait = c(agree = "Agreeableness", consc = "Conscientiousness",
                                  stabi = "Stability", extra = "Extraversion", openn = "Openness"))
# plot
plot.fe1 <- ggplot(dat, aes(x=religion, y=mean)) +
  geom_bar(stat="identity", position="dodge", fill="black", alpha=0.3) +
  geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), width = 0.3) + 
  facet_wrap(. ~ trait, labeller = labeller_bf) + 
  labs(y="Mean", x="Religiosity") +
  scale_x_discrete(labels=c("Secular", "Traditional", "Religious", 
                            "Very Religious\n/Ultra-Orthodox")) +
  scale_y_continuous(breaks=c(0,0.25,0.5,0.7), 
                     labels=c("0", "0.25", "0.5", "0.75")) +
  theme_bw() +
  theme(
    panel.grid = element_blank(),
    axis.text.x = element_text(angle = 45, hjust=1),
  )

# save file
ggsave("Figure E1.pdf", plot=plot.fe1,  width=6, height=4)
